/*
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package hextd.util;

public class SiFormatter {

	public static char[] prefixLarge = {'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};

	public static String format(int number) {
		return format(number, 10000);
	}

	public static String format(long number) {
		return format(number, 10000);
	}

	public static String format(int number, int limit) {
		String retval;
		int pointer = -1;
		while (number > limit && pointer < prefixLarge.length - 1) {
			number /= 1000;
			pointer++;
		}
		retval = "" + number;
		if (pointer >= 0) {
			retval += " " + prefixLarge[pointer];
		}
		return retval;
	}

	public static String format(long number, int limit) {
		String retval;
		int pointer = -1;
		while (number > limit && pointer < prefixLarge.length - 1) {
			number /= 1000;
			pointer++;
		}
		retval = "" + number;
		if (pointer >= 0) {
			retval += " " + prefixLarge[pointer];
		}
		return retval;
	}
}
